package pl.nazaweb.imedproplus.model.entity;

import pl.nazaweb.imedproplus.model.interfaces.IIcd10;
import java.io.Serializable;
import java.util.List;
import javax.persistence.*;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

@Entity
@Table(name = "icd10")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Icd10.findAll", query = "SELECT i FROM Icd10 i"),
    @NamedQuery(name = "Icd10.findByCode", query = "SELECT i FROM Icd10 i WHERE i.code = :code"),
    @NamedQuery(name = "Icd10.findByName", query = "SELECT i FROM Icd10 i WHERE i.name = :name")})
public class Icd10 implements Serializable, IIcd10 {
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "icd10")
    private List<Diagnosis> diagnosisList;
    private static final long serialVersionUID = 1L;
    @Id
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 10)
    @Column(name = "code")
    private String code;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 500)
    @Column(name = "name")
    private String name;
    @JoinTable(name = "diagnosis", joinColumns = {
        @JoinColumn(name = "icd10", referencedColumnName = "code")}, inverseJoinColumns = {
        @JoinColumn(name = "visit", referencedColumnName = "id")})
    @ManyToMany
    private List<Visit> visitList;
    @OneToMany(mappedBy = "diagnosis")
    private List<Referral> referralList;

    public Icd10() {
    }

    public Icd10(String code) {
        this.code = code;
    }

    public Icd10(String code, String name) {
        this.code = code;
        this.name = name;
    }

    @Override
    public String getCode() {
        return code;
    }

    @Override
    public void setCode(String code) {
        this.code = code;
    }

    @Override
    public String getName() {
        return name;
    }

    @Override
    public void setName(String name) {
        this.name = name;
    }

    @XmlTransient
    @Override
    public List<Visit> getVisitList() {
        return visitList;
    }

    @Override
    public void setVisitList(List<Visit> visitList) {
        this.visitList = visitList;
    }

    @XmlTransient
    @Override
    public List<Referral> getReferralList() {
        return referralList;
    }

    @Override
    public void setReferralList(List<Referral> referralList) {
        this.referralList = referralList;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (code != null ? code.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Icd10)) {
            return false;
        }
        Icd10 other = (Icd10) object;
        if ((this.code == null && other.code != null) || (this.code != null && !this.code.equals(other.code))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "pl.nazaweb.imedproplus.model.entity.Icd10[ code=" + code + " ]";
    }

    @XmlTransient
    @Override
    public List<Diagnosis> getDiagnosisList() {
        return diagnosisList;
    }

    @Override
    public void setDiagnosisList(List<Diagnosis> diagnosisList) {
        this.diagnosisList = diagnosisList;
    }

}
